﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            string filePath = @"E:\tmp\test.txt";
            for (int j = 0; j < 10; j++)
            {
                Task.Run(() =>
                {
                    var fs = File.Open(filePath, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite);
                    var buffer = Encoding.Default.GetBytes(GenerateTempName(new Random().Next(0, 10)));

                    fs.Position = fs.Length;
                    fs.Write(buffer, 0, buffer.Length);
                    fs.Flush();
                    fs.Close();
                    fs.Dispose();

                    FileInfo info = new FileInfo(filePath);

                    Console.WriteLine("info length:" + info.Length);

                    Thread.Sleep(500);
                });
            }

            Console.ReadKey();

        }
        /// <summary>
        /// 生成临时文件名称
        /// </summary>
        /// <param name="index"></param>
        /// <returns></returns>
        private static string GenerateTempName(object index)
        {
            string res = index.ToString().PadLeft(16, '0');
            return res;
        }


        private static void Test()
        {
           
        }

    }
}
